from keywords_a3mall.Base import Base
import openpyxl,pytest
from selenium import webdriver

@pytest.fixture(scope='session')
def driver():

    driver = webdriver.Edge()
    driver.maximize_window()
    yield driver
    driver.quit()

def test_login(driver):

    # 获取excel表格数据
    work = openpyxl.load_workbook('a3mall_keywords.xlsx')
    # 读取excel，Sheet1表中的数据
    excel = work['Sheet1']
    # 初始化驱动
    base = Base(driver)
    # 循环读取数据
    for row in excel.iter_rows(min_row=2,values_only=True):
        # 从第二行开始读取
        action = row[2]
        params = {}
        # 打开网址
        if action == 'goto':
            params['url'] = row[5]
        # 定位元素
        elif action in ['send_keys','click','text']:
            params['loc'] = [row[3],row[4]]
            print(row[3])
            print(row[4])

            if action == 'send_keys':
                params['text'] = row[5]
        # 强制等待
        if action == 'sleep':
            params['timeout'] = row[5]

        method = getattr(base, str(action))
        method(**params)